Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

feature/settings/src/androidMain/kotlin/org/meshtastic/feature/settings/tak/TakPermissionUtil.kt f5e5fb6da63ee85e64dbbe19a519a5a3deccd408 (f5e5fb6d) Text, 2.43 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.settings.tak

Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.LaunchedEffect
Tff7b72import T7ee787org.meshtastic.core.ui.util.isLocalNetworkPermissionGranted
Tff7b72import T7ee787org.meshtastic.core.ui.util.rememberRequestLocalNetworkPermission

Tf0883e@Composable
Tff7b72actual Tff7b72fun Td2a8ffTakPermissionHandlerTb4b4b4(Te6edf3isTakServerEnabledTb4b4b4: Tffa657BooleanTb4b4b4, Te6edf3onPermissionResultTb4b4b4: Tb4b4b4(Tffa657BooleanTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
T8b949e// ACCESS_LOCAL_NETWORK runtime permission (Android 17 / API 37+) is required for the TAK Server's
T8b949e// localhost socket binding (127.0.0.1:8087). It is also required globally for NSD/mDNS device discovery
T8b949e// when targetSdk >= 37, and is requested up-front from the Connections screen, so it will usually
T8b949e// already be granted by the time the user enables TAK. This composable handles the standalone case
T8b949e// (e.g. user opens TAK settings before ever tapping the network-scan toggle).
Tff7b72val Te6edf3isPermissionGranted Tff7b72= Te6edf3isLocalNetworkPermissionGrantedTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3requestPermission Tff7b72=
Te6edf3rememberRequestLocalNetworkPermissionTb4b4b4(
Te6edf3onGranted Tff7b72= Tb4b4b4{ Te6edf3onPermissionResultTb4b4b4(Tff7b72trueTb4b4b4) Tb4b4b4}Tb4b4b4,
Te6edf3onDenied Tff7b72= Tb4b4b4{ Te6edf3onPermissionResultTb4b4b4(Tff7b72falseTb4b4b4) Tb4b4b4}Tb4b4b4,
Tb4b4b4)

T8b949e// The launcher must run as a post-composition side effect — invoking it directly in the composition
T8b949e// body crashes with "Launcher has not been initialized" because the underlying
T8b949e// ActivityResultLauncherHolder is not linked to the activity until composition completes. Keying on
T8b949e// both inputs also guarantees we only re-prompt when state actually transitions, not on every
T8b949e// recomposition.
Te6edf3LaunchedEffectTb4b4b4(Te6edf3isTakServerEnabledTb4b4b4, Te6edf3isPermissionGrantedTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3isTakServerEnabled Tff7b72&Tff7b72& Tff7b72!Te6edf3isPermissionGrantedTb4b4b4) Tb4b4b4{
Te6edf3requestPermissionTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.03s